export class StatusBar {
  public _sendBytes = 0;
  public _reciveBytes = 0;
  public _frameRate = 0;
  public _owner;
  public _title;
  constructor(owner: any, title: string) {
    this._owner = owner;
    this._title = title;
    this._updateTextContent('status_title', this._title);
    setInterval(() => {
      this._ResetStatus();
    }, 1000);
  }

  _ResetStatus() {
    this._updateTextContent('send_bytes', String(this._sendBytes));
    this._updateTextContent('recive_bytes', String(this._reciveBytes));
    this._updateTextContent('frame_rate', String(this._frameRate));
    this._sendBytes = 0;
    this._reciveBytes = 0;
    this._frameRate = 0;
  }

  updateSend(sendBytes: any) {
    if (typeof sendBytes === 'number') {
      this._sendBytes += sendBytes;
    }
  }

  updateRecive(reciveBytes: any) {
    if (typeof reciveBytes === 'number') {
      this._reciveBytes += reciveBytes;
    }
  }

  updateFrame(frameRate: any) {
    this._frameRate += frameRate;
  }

  private _updateTextContent(elementId: string, value: string) {
    const target = document.getElementById(elementId);
    if (!target) {
      return;
    }
    target.innerText = value;
  }
}
